import $ from '../../utils/ajax.js';
import util from '../../utils/util.js';
const app = getApp();
Page({
    data: {
        content: [],
        //array: [0, 1, 2, 3, 4, 5, 6, 10]
        array: ['全部', '服务费', '运营费', '租金', '会员费', '提现', '订单逾期', '订单补贴'],
        list: {
            page: 1,
            size: 10,
            orderType: 0,
            incomeOrOut: 0,
            timeType: 1,
        }
    },
    onLoad(options) {
        this.onIncomeList();
    },
    bindPickerChange(e) {
        const value = Number(e.detail.value);
        this.setData({
            'list.orderType': value === 7 ? 10 : value,
            'list.page': 1,
        }, () => {
            this.onIncomeList();
        })
    },
    onIout({ target: { dataset: { id } } }){
        this.setData({
            'list.incomeOrOut': Number(id) === this.data.list.incomeOrOut ? 0 : Number(id),
            'list.page': 1,
        }, () => {
            this.onIncomeList();
        })
    },
    onType({ target: { dataset: { id } } }) {
        this.setData({
            'list.timeType': Number(id),
            'list.page': 1,
        }, () => {
            this.onIncomeList();
        })
    },
    onIncomeList(){
        $.p(app.wxApp.url + 'agentincome/incomeList', {...this.data.list}, app.onStrart, (res) => {
            let prime = [];
            if (res.data.page === 1) {
                prime = res.data.list;
            } else {
                prime = this.data.content.concat(res.data.list);
            }
            this.setData({
                content: prime
            })
            app.onShop();
        }, (res) => {
            util.showToast(res.data)
        })
    },
    onReachBottom(e) {
        this.setData({
            ['list.page']: this.data.list.page + 1
        }, () => {
            this.onIncomeList();
        })
    }
})